package com.eveinfo.display.asset;

import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.eveinfo.R;
import com.eveinfo.display.SheetView;
import com.eveinfo.sql.data.Item;
import com.eveinfo.tools.Logging;
import com.eveinfo.tools.Tools;

public class ItemView extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.item);

		int typeID = getIntent().getIntExtra("typeID", -1);

		try {
			ArrayList<Item> types = SheetView.getItems();
			Item item = null;
			for (Item type : types) {
				if (type.getTypeID() == typeID) {
					item = type;
					break;
				}
			}
			if (item == null) {
				finish();
				return;
			}

			ImageView imageView = (ImageView) findViewById(R.id.IVItem);
			imageView.setImageDrawable(Tools.getItemPicture(item, 64));

			TextView nameTV = (TextView) findViewById(R.id.TVItemName);
			nameTV.setText(item.getTypeName());

			TextView infoTV = (TextView) findViewById(R.id.TVItemInfo);
			infoTV.setText("Number: " + item.getQuantity());

			ListView listView = (ListView) findViewById(R.id.LVItem);
			new ItemAdapter(this, R.layout.itemr, listView, item);

		} catch (Exception e) {
			Logging.getInstance().e(e);
			e.printStackTrace();
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setTitle(e.toString());
			builder.setMessage(e.getMessage());
			builder.show();
			finish();
		}

	}

}
